package com.hk.parse;

public class SqlParse {

	/**
	 *  select * from t_user where id = #{id}
	 * @param sql
	 * @return select * from t_user where id = ?
	 */
	public static String parse(String sql) {
		StringBuilder sb = new StringBuilder();
		char[] charArray = sql.toCharArray();
		for(int i=0;i<charArray.length;) {
			if(charArray[i]=='#') {
				while(charArray[i++]!='}') {
					if(i>=charArray.length)
						throw new RuntimeException("请检查sql语句格式是否正确"+sql);
				}
				sb.append('?');
			}else {
				sb.append(charArray[i]);
				i++;
			}
		}
		return sb.toString();
	}
//	public static void main(String[] args) {
//		String sql =" select * from t_user where id = #{id}";
//		System.out.println(SqlParse.parse(sql));
//	}
}
